<template>
<div class="management-user-edit views-container">
  <div class="wlm-form">
    <div class="wlm-form-header">用户编辑</div>
    <div class="wlm-form-content">
      <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
        <el-form-item label="登录账号" prop="user_name">
          <el-input v-model.trim="formFormatData.formData.user_name">
          </el-input>
          <div class="form-help">请输入11位手机号</div>
        </el-form-item>
        <el-form-item label="姓名" prop="nickname">
          <el-input v-model.trim="formFormatData.formData.real_name">
          </el-input>
          <div class="form-help">主要用于平台展示</div>
        </el-form-item>
        <el-form-item label="密码">
          <el-input  v-model.trim="formFormatData.formData.password">
          </el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="formFormatData.formData.is_use">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="平台名称">
          <span>{{formFormatData.formData.platform_name || '-'}}</span>
          <router-link tag="span" :to="{path:'/platform/managementPlatformAdd',query:{redirect:'useradd',uid:formFormatData.formData.store_user_id,nickname:formFormatData.formData.user_name}}">
          <el-button type="text" style="font-size:14px;">创建平台</el-button>
          </router-link>
        </el-form-item> -->
      </el-form>
    </div>
  </div>
  <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
    <el-button size="small" @click="formFormatSubmit({ router: { type: 'replace', path: '/user/managementAdminUser', code: 1 }})" type="primary">保存</el-button>
    <router-link tag="span" to="/user/managementAdminUser">
      <el-button size="small">返回</el-button>
    </router-link>
  </div>
</div>
</template>

<script>
import {
  userAdd,
  memberDetail
} from '@/api/user'
import {
  regPhone
} from '@/utils/regular'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'ManagementUserEdit',
  components: {

  },
  created() {
    if (this.$store.getters.beforepath === '/user/managementAdminUser') {
      this.$store.dispatch('setRedirect', '/platform/managementPlatformAdd')
      this.$store.dispatch('toggleDropdown', true)
    } else if (this.$store.getters.beforepath === '/platform/managementPlatformAdd') {
      this.$store.dispatch('setRedirect', '/user/managementAdminUser')
    }
  },
  directives: {

  },
  data() {
    var mobile = (rule, value, callback) => {
      if (!regPhone(value)) {
        return callback(new Error('注册手机号格式不正确'))
      } else {
        callback()
      }
    }
    return {
      formFormatData: {
        key: 'userForm',
        api: {
          editForm: {
            api: memberDetail
          },
          submitForm: userAdd
        },
        formData: {
          real_name: '',
          repassword: '',
          password: '',
          user_name: '',
          is_use: 1
        },
        rules: {
          real_name: [{
            required: true,
            message: '请输入真实姓名',
            trigger: 'blur'
          }],
          user_name: [{
            required: true,
            message: '请输入登录账号',
            trigger: 'blur'
          },
          {
            validator: mobile,
            trigger: 'blur'
          }
          ]
        }
      }
    }
  },
  mounted() {

  },
  methods: {

  }
}
</script>
